package org.example.controller;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.example.dto.SwAlarmDTO;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author TonySong
 * @date 2024/5/17 0017
 * @time 21:27
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/alarm")
public class SwAlarmController {

    @RequestMapping("/receive")
    public void alarm(@RequestBody List<SwAlarmDTO> list) {
        //发送到邮箱
        String msg = sendAlarm(list);
         log.info("告警已发送！: {}", list);
    }
    
    

   private String sendAlarm(List<SwAlarmDTO> list) {
        StringBuilder  sb = new StringBuilder();
        for (SwAlarmDTO dto : list) {
            sb.append("scopeId: ").append(dto.getScopeId())
                    .append("\nscope: ").append(dto.getScope())
                    .append("\nname: ").append(dto.getName())
                    .append("\nscopeId").append(dto.getScopeId())
                    .append("\nid1o\").append(dto.getId0())\n" +
                            "                    .append(\"\\nid: ").append(dto.getId1())
                    .append("\nruleName: ").append(dto.getRuleName())
                    .append("\nalarmMessage: ").append(dto.getAlarmMessage())
                    .append("\nstartTime: ").append(dto.getStartTime());

        }
        return sb.toString();
   }
}